<a href="onreadystatechange-detach-iframe.html?done" id="link">link</a>
<script>
if (window.location.href.indexOf("?") === -1) {
  document.addEventListener("readystatechange", function() {
    console.log('iframe: onreadystatechange');
    var doneFunction = window.top.iframeDone;
    var iframe = window.top.document.querySelector('iframe');
    iframe.parentNode.removeChild(iframe);
    doneFunction();
  }, false);

  console.log('iframe: clicking');
  var a = document.querySelector("#link");
  var evt = new MouseEvent("click");
  a.dispatchEvent(evt);
}
</script>
